package diamond

import (
	"errors"
	"strings"
)

const testVersion = 1

func Gen(char byte) (diamond string, e error) {
	if char < 65 || char > 90 {
		e = errors.New("char error")
		return
	}

	var diamonds []string
	step := char - 65
	length := step*2 + 1
	dia := make([][]byte, length)
	f := len(dia) / 2

	for i := 0; i < len(dia); i++ {
		dia[i] = make([]byte, length)
		for j := 0; j < len(dia[i]); j++ {
			dia[i][j] = ' '
		}
		t := 0
		if f >= i {
			t = i
		} else {
			t = 2*f - i
		}
		dia[i][f-t] = byte('A' + t)
		dia[i][f+t] = byte('A' + t)

		diamonds = append(diamonds, string(dia[i]))
	}

	diamonds = append(diamonds, "") // magic
	diamond = strings.Join(diamonds, "\n")
	return
}
